home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher1.12 / misc / newitems.pl / text0000.txt < prev   
Encoding:
Text File  |  1992-10-19  |  4.0 KB  |  179 lines

  1. We wanted to be able to provide a listing of new/recently changed items
  2. in our Gopher server.  The attached script is the tool I developed to 
  3. provide this.  It generates a link file, so the listing is a directory,
  4. not a flat file.  The user-visible name is carried over.
  5.  
  6. Usage:  newitems /disk/path/name -#daysold server.domain.name #port
  7.  
  8. The link file it generates is called .newlinks in the current directory.
  9. If you place a file called .nonew in a directory, that directory is skipped.
  10. If you place a file called .topnew in a directory, that directory will be
  11. listed if any new files are found in that directory or its subdirectories.
  12. This script depends on the gopherls tool which is a link to the gopherd 
  13. program, starting with version (approx) 1.0.  You'll obviously be needing
  14. Perl.
  15.  
  16. This script seems to be working for me, but hasn't been tested exhaustively.
  17.  
  18. Dennis
  19. ----------------------------------------------------------------------
  20. #!/usr/local/bin/perl
  21. # newitems, boone, 09/30/92
  22. # Generate a link file listing new items in the last n days
  23. # Copyright (C) 1992, Trustees of Michigan State University
  24. #
  25. # Modifications:
  26. # 09/30/92 Boone      Initial coding
  27. # 10/01/92 Boone      Added ability to exclude individual directories
  28. # End Modifications
  29.  
  30. # Extract path part of pathname
  31.  
  32. sub path
  33. {
  34.     local($path) = @_;
  35.     local($pathsep) = rindex($path, "/");
  36.     if ($pathsep < 0)
  37.     {
  38.         return "";
  39.     }
  40.     else
  41.     {
  42.         $wanted = substr($path, 0, $pathsep+1);
  43.         return $wanted;
  44.     }
  45. }
  46.  
  47. # Extract filename part of pathname
  48.  
  49. sub base
  50. {
  51.     local($path) = @_;
  52.     local($pathsep) = rindex($path, "/");
  53.     if ($pathsep < 0)
  54.     {
  55.         return $path;
  56.     }
  57.     else
  58.     {
  59.         $wanted = substr($path, $pathsep+1);
  60.         return $wanted;
  61.     }
  62. }
  63.  
  64. # Determine whether this item is part of a subtree which wants to be
  65. # announced as a single new entry if any file in it has changed.  <pant>
  66. # Example: /news/newspapers/state_news contains a file called .topnew,
  67. # indicating that any file in the state news subtree will cause the
  68. # /news/newspapers/state_news entry to be listed once in the new items
  69. # list.
  70.  
  71. sub skip
  72. {
  73.     local(@args) = @_;
  74.     foreach $i (@topnew)
  75.     {
  76.         if (index($args[0], $i) == 0)
  77.         {
  78.             $toplist{$i} = $args[0];
  79.             return 1;
  80.         }
  81.         else
  82.         {
  83.         }
  84.     } 
  85.     return 0;
  86. }
  87.  
  88. # Write a link file entry
  89.  
  90. sub writelink
  91. {
  92.     local($line, $path) = @_;
  93.     local(@fields) = split(/\t/, $line);
  94.     local($name) = substr($fields[0], 1);
  95.     local($type) = substr($fields[0], 0, 1);
  96.     print LF "Name=$name\nType=$type\nPath=$path\nHost=$host\nPort=$port\n\n";
  97. }
  98.  
  99. # The real code
  100.  
  101. $[ = 0;
  102. if ($#ARGV < 3)
  103. {
  104.     print STDERR "Usage: newitems  path days host port\n";
  105.     exit(1);
  106. }
  107.  
  108. open(LF, ">.newlinks") || die "Unable to create .newlinks\n";
  109. chdir($ARGV[0]);
  110. chop($here = `pwd`);
  111. $days = $ARGV[1];
  112. $host = $ARGV[2];
  113. $port = $ARGV[3];
  114.  
  115. @topnew = `find . -name .topnew -print`;
  116. foreach $i (@topnew)
  117. {
  118.     $i = &path($i);
  119. }
  120. open(NF, "find . -mtime $days -type f -print | grep -v .cap |") || 
  121.     die "Unable to spawn find\n";
  122. while (<NF>)
  123. {
  124.     next if /\.cap/;
  125.     next if /\.ts/;
  126.     next if /\.bin/;
  127.     chop;
  128.     $path = &path($_);
  129.     $base = &base($_);
  130.     next if ($base =~ /^\./);
  131.     chdir($path) || die "chdir($path) died: $!\n";
  132.     if (! -f ".nonew")
  133.     {
  134.         @lines = `/usr/local/etc/gopherls .`;
  135.         foreach $i (@lines)
  136.         {
  137.             chop($i); chop($i);
  138.             @fields = split(/\t/, $i);
  139.             $thisname = substr($fields[1], 2);
  140.             if ($thisname eq $base)
  141.             {
  142.                 if (! &skip($_))
  143.                 {
  144.                     &writelink($i, $_);
  145.                 }
  146.             }
  147.             undef(@fields);
  148.         }
  149.         undef(@lines);
  150.     }
  151.     chdir($here) || die "chdir($here) died: $!\n";
  152. }
  153. foreach $i (keys %toplist)
  154. {
  155.     chop($i);
  156.     $base = &base($i);
  157.     chdir($i) || die "chdir($path) died: $!\n";
  158.     chdir("..") || die "chdir(..) died: $!\n";
  159.     @lines = `/usr/local/etc/gopherls .`;
  160.     foreach $j (@lines)
  161.     {
  162.         chop($j); chop($j);
  163.         @fields = split(/\t/, $j);
  164.         $thisname = substr($fields[1], 2);
  165.         if ($thisname eq $base)
  166.         {
  167.             &writelink($j, $i);
  168.         }
  169.         undef(@fields);
  170.     }
  171.     undef(@lines);
  172.     chdir($here) || die "chdir($here) died: $!\n";
  173. }
  174. close(NF);
  175. close(LF);
  176. --
  177.  == If you choose not to decide, you still have made a choice. ==
  178.  
  179.